﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Collections;
using System.Runtime.InteropServices;

using SuperMapLib;

namespace JR_RouteAlarm
{
    class Route : IRoute
    {
        /*定数*/
        public const string FEATURE_CD = Utility.FEATURE;
        public const string DAIBUN_CD = Utility.DAIBUN;
        public const string TSUUSHO_CD = Utility.TSUUSHO;

        #region IRoute メンバ

        private string feature = String.Empty;
        public string Feature
        {
            get
            {
                return feature;
            }
            set
            {
                feature = value;
            }
        }

        private string daibun = String.Empty;
        public string Daibun
        {
            get
            {
                return daibun;
            }
            set
            {
                daibun = value;
            }
        }

        private string tsuusho = String.Empty;
        public string Tsuusho
        {
            get
            {
                return tsuusho;
            }
            set
            {
                tsuusho = value;
            }
        }

        public static Hashtable routePartsPair = new Hashtable();

        //private Hashtable routePartsPair = null;
        //public Hashtable RoutePartsPair
        //{
        //    get
        //    {
        //        return routePartsPair;
        //    }
        //    set
        //    {
        //        routePartsPair = value;
        //    }
        //}

        //public void MakePartsForRoute(soRecordset objRS, soGeometry objMetry)
        //{
        //    if (objRS != null && !(objRS.IsBOF() && objRS.IsEOF()))
        //    {
        //        if (!objRS.IsBOF())
        //        {
        //            objRS.MoveFirst();
        //        }
        //        //string[] routeParts = null;
        //        for (int i = 0; i < objRS.RecordCount || !objRS.IsEOF(); objRS.MoveNext(), i++)
        //        //for (; !objRS.IsEOF(); objRS.MoveNext())
        //        {
        //            feature[i] = objRS.GetFieldValue(FEATURE_CD).ToString();
        //            daibun[i] = objRS.GetFieldValue(DAIBUN_CD).ToString();
        //            tsuusho[i] = objRS.GetFieldValue(TSUUSHO_CD).ToString();
        //            //routeParts[0] = feature;
        //            //routeParts[1] = daibun;
        //            //routeParts[2] = tsuusho;
        //       }
        //       routePartsPair[objMetry] = new String[] { feature, daibun, tsuusho };
        //   }
        //}

        public void MakePartsForRoute(soDatasetVector objVector, soRecordset objRS)
        {
            soRecordset objSubRs = null;

            objSubRs = objVector.Query(
                FEATURE_CD + " = '" + objRS.GetFieldValue(FEATURE_CD) + "' and " +
                DAIBUN_CD + " = '" + objRS.GetFieldValue(DAIBUN_CD) + "' and " +
                TSUUSHO_CD + " = '" + objRS.GetFieldValue(TSUUSHO_CD) + "'",
                true, null, "");

            if (objSubRs != null && !(objSubRs.IsBOF() && objSubRs.IsEOF()))
            {
                if (!objSubRs.IsBOF())
                {
                    objSubRs.MoveFirst();
                }
                feature = objSubRs.GetFieldValue(FEATURE_CD).ToString();
                daibun = objSubRs.GetFieldValue(DAIBUN_CD).ToString();
                tsuusho = objSubRs.GetFieldValue(TSUUSHO_CD).ToString();

                ArrayList listLine = new ArrayList();
                for (int i = 0; i < objSubRs.RecordCount || !objSubRs.IsEOF(); objSubRs.MoveNext(), i++)
                //for (; !objSubRs.IsEOF(); objSubRs.MoveNext())
                {
                    listLine.Add(objSubRs.GetGeometry());
                }
                routePartsPair[new String[] { feature, daibun, tsuusho }] = listLine;

                Marshal.ReleaseComObject(objSubRs);
                objSubRs = null;
            }
        }

        #endregion
    }
}
